/**
 * 文件目录js
 */

$(function () {
	initialPage();
	getGrid();
});

function initialPage() {
	$(window).resize(function() {
		$('#dataGrid').bootstrapTable('resetView', {height: $(window).height()-56});
	});
}

function getGrid() {
    var roomId = Utils.dialogArgs()['classRoomId'];
	$('#dataGrid').bootstrapTableEx({
		url: '../../srblive/file/list?_' + $.now(),
		height: $(window).height()-56,
		queryParams: function(params){
		    vm.keyword.classRoomId = roomId;
			params.keyword = vm.keyword;
			return params;
		},
        // pagination: false,
		columns: [
			{checkbox: true},
			// {field : "openId", title : "openid", width : "100px"},
			// {field : "classroomId", title : "课程id", width : "100px"},
			{field : "fileName", title : "文件名", width : "100px"}, 
			{field : "fileUrl", title : "文件路径", width : "100px"}, 
			{field : "fileSize", title : "文件大小", width : "100px"/*,formatter:FormatterJS.formateSize*/},
            // {field : "1", title : "操作", width : "100px",
            //     formatter:function(value, row, index) {
            //         // var retStr = '<span class="btn label label-success" onclick="Utils.download(\''+row.fileUrl+'\',\''+row.fileName+'\');">下载</span>';
            //         var retStr = '';
            //         retStr += '&nbsp;<span class="btn label label-success" onclick="Utils.uploadDlg(\''+row.id+'\');">上传PPT</span>';
            //         return retStr;
            //     }
            // },
		]
	})
}

var vm = new Vue({
	el:'#dpLTE',
	data: {
		keyword: {
            classRoomId:null,
		    key:null,
        }
	},
	methods : {
		load: function() {
			$('#dataGrid').bootstrapTable('refresh');
		},
		save: function() {
			dialogOpen({
				title: '新增文件目录',
				url: 'srblive_html/file/add.html?_' + $.now(),
                width: '80%',
                height: '80%',
				yes : function(iframeId) {
					top.frames[iframeId].vm.acceptClick();
				},
			});
		},
		edit: function() {
			var ck = $('#dataGrid').bootstrapTable('getSelections');
			if(checkedRow(ck)){
				dialogOpen({
					title: '编辑文件目录',
					url: 'srblive_html/file/edit.html?_' + $.now(),
                    width: '80%',
                    height: '80%',
					success: function(iframeId){
						top.frames[iframeId].vm.srbliveFile.id = ck[0].id;
						top.frames[iframeId].vm.setForm();
					},
					yes: function(iframeId){
						top.frames[iframeId].vm.acceptClick();
					}
				});
			}
		},
		remove: function() {
			var ck = $('#dataGrid').bootstrapTable('getSelections'), ids = [];	
			if(checkedArray(ck)){
				$.each(ck, function(idx, item){
					ids[idx] = item.id;
				});
				$.RemoveForm({
					url: '../../srblive/file/remove?_' + $.now(),
			    	param: ids,
			    	success: function(data) {
			    		vm.load();
			    	}
				});
			}
		},
        //导入弹窗
        uploadDlg:function (classRoomId) {
            dialogOpen({
                title: '上传PPT',
                url: 'srblive_html/file/upload.html?_' + $.now(),
                width: '40%',
                height: '45%',
                // btnSize: 1,
                btnAlign: 'c',
                btn:[],
                success: function(iframeId){
                    top.frames[iframeId].vm.classRoomId = classRoomId;
                },
                yes: function(iframeId){
                    top.frames[iframeId].vm.acceptClick();
                }
            });
        },
	},
    mounted:function () {
        setTimeout(function() {
            AjaxUploadUtils.pptInit({
                targetId:'upload',
                data:{
                    classRoomId:vm.keyword.classRoomId,
                    token:token
                },
                success:function(file, r){
                    vm.load();
                },
            });
        },500);
    }
})